<?php 
include('includes/confirm.php');
$page_name = friends;
require_once 'classes/Mysql.php';
//require_once 'includes/constants.php';
$mysql = New Mysql();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <?php include('includes/head.php'); ?>
<body>
<div id="wrapper">
    <?php include('includes/header.php'); ?>
    <?php include('includes/menu.php'); ?>
    
    <div id="page">
    	
	      <div id="content">
			<form method="post" action="">
				<h2> Delete Friend </h2>
				<br>Friend's user id:
				<input type="text" name="user_id" value=""/>
				<input type="submit" name="add_submit" value="Delete"/>
			</from>
			<?php
				
				if($_POST && !empty($_POST['email'])){

					$stmt = $mysql->run_query("SELECT id, uname
												FROM user
												WHERE uname = ? 
													AND id IN (SELECT id2 
																	FROM friend
																	WHERE id1=?)", $_POST['user_id'], $_SESSION['userid']);
					$stmt->bind_result($id, $user);
					if($stmt->fetch()){
						// add user
						$stmt->close();
						$stmt = $mysql->run_query("DELETE FROM friend 
													WHERE id1 = ? AND id2=?", $_SESSION['userid'], $id);
						echo "<br><br><h4>Deleted Friend: $user<h4>";
					}
					else{
						echo "<br><br><h4>User is not a friend!<h4>";
					}
				}
			?>
	      </div>
	      <!-- end div#content -->
	      <div id="sidebar">
			<ul>
				<li><h1><a href="friends.php">Browse</a></h1><br></li>
				<li><h1><a href="add_friend.php">Add</a></h1><br></li>
				<li><h1><a href="delete_friend.php">Delete</a></h1><li>
			</ul>
	      </div>
	      <!-- end div#sidebar -->
	      <div style="clear: both; height: 1px"></div>
	   
	  </div>
  
  	</div>
  	<!-- end div#page -->
    <?php include('includes/footer.php'); ?>
</div> <!-- end div#wrapper -->
</body>
</html>
